<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<script>

    // 被观察者
    class Dep {
        constructor(props) {
            this.subs = []
        }

        addSub(watcher) {
            //     收集watcher
            this.subs.push(watcher)
        }

        // 通知wathcer更新
        notify() {
            this.subs.forEach(watcher => watcher.update())
        }
    }

    class Watcher {
        constructor(name) {
            this.name = name
        }

        update() {
            console.log(`${this.name} - 电影2023 - 5 - 6上映`);
        }
    }

    // 数据进行响应式处理之前
    const dep = new Dep()

    dep.addSub(new Watcher('应豪'))
    dep.addSub(new Watcher('刘泽'))
    dep.addSub(new Watcher('汪卫斌'))
    dep.addSub(new Watcher('刘兴'))

    // 如何更新依赖
    setTimeout(() => {
        dep.notify()
    }, 1000)
</script>
</body>
</html>
